﻿package com.toncen.samepms.net.action;

import java.util.Date;
import java.util.Map;

import com.toncen.samepms.common.AbstractDatabaseAction;
import com.toncen.samepms.net.dao.SuggestionDao;
import com.toncen.samepms.net.domain.Suggestion;
import com.opensymphony.xwork2.ActionContext;

/**
 * 描述：意见反馈表NET_SUGGESTION的action文件
 * 
 * @author tch
 * 
 */
public class SuggestionAction  extends AbstractDatabaseAction<Suggestion, SuggestionDao>{
	/**
	 * 序列号
	 */
	private static final long serialVersionUID = 1370398878067L;

	public SuggestionAction() throws Exception{
		super();
	}
	
	/**
	 * 验证码
	 */
	private String valildateCode;
	
	public String onDoSuggest(){
		return SUCCESS;
	}
	
	/**
	 * 添加获取session的方法
	 * 
	 * @return Map(session)
	 * @author:黄忠义
	 */
	protected Map getSession() {
		return ActionContext.getContext().getSession();
	}
	
	/**
	 * 验证注册码
	 * @author Mark
	 * @throws Exception
	 */
	protected void checkValidateCode(String validateCode) throws Exception{
		if("".equals(validateCode)||validateCode == null) {
			throw new Exception("请输入验证码!");
		} else {
			if(!validateCode.equals(getSession().get("random"))){
				throw new Exception("验证码【"+validateCode+"】错误,请重新输入");
			} 
		}

	}
	
	public String onDoUpSuggest() throws Exception{
		//checkValidateCode(getValildateCode());// 验证码
		Suggestion suggestion=(Suggestion) getDomain();
		suggestion.setCreatedate(new Date());
		suggestion.setState(2);//否
		save(suggestion);
		return SUCCESS;
	}
	
	public void prepareOnDoSave() throws Exception {
		super.prepareOnDoSave();
		Suggestion suggestion=(Suggestion) getDomain();
		suggestion.setReplayer(getCurrentUser());
		suggestion.setReplaydate(new Date());
		suggestion.setState(1);//是
	}
	

	public String getValildateCode() {
		return valildateCode;
	}

	public void setValildateCode(String valildateCode) {
		this.valildateCode = valildateCode;
	}
}
